<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>账户异动列表</title>

    <!--引用div做成的下拉框效果样式-->
    <link rel="stylesheet" href="/quanliadmin/docroot/css/department_select.css" type="text/css" media="screen" />

    <!--引用div做成的下拉框效果js-->
    <script language="JavaScript" src="/quanliadmin/docroot/js/department_select.js" type="text/javascript"></script>
</head>
<body>
<style>
    .imageSites{
        position: absolute;
        left:335px;
        top:58px;
    }
</style>
<div class="container">

    <div class="comm_content">
            <div class="search-box">
                <div style="position:relative">
                    <form id="search_form" class="form-inline" onsubmit="return false;">
                        <table>
                            <tbody>
                            <tr>
                                <td>
                                    <span>流水号：<input type="text" id="changeID" class="form-control input-sm"  name="changeID" value="" style="width:120px;"/></span>
                                    <span>客户名称：<input type="text" id="custName" class="form-control input-sm"  name="custName" value="" style="width:150px;"/></span>
                                    <span>异动状态：<select id="changeStatus" class="form-control input-sm"  name="changeStatus" style="width:100px;">
                                            <option value="0">请选择</option>
                                            <option value="1">应收</option>
                                            <option value="2">实收</option>
                                        </select>
                                    </span>
                                    <span>
                                        创建日期：<input class="form-control input-sm w100" id="startDate" name="startDate" value="" readonly="readonly"   type="text" />
                                        ～
                                        <input class="form-control input-sm w100" id="endDate" name="endDate" value="" readonly="readonly" type="text" " />
                                        <button type="button" class="btn btn-default btn-sm" onclick="timeClear1();">清 空</button>
                                    </span>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <span>
                                        部 门：
                                    </span>
                                        <span style="vertical-align: middle">
                                            <div class="search_option">
                                                <div class="search_option_drop" >
                                                    <span id="searchOptions">
                                                        请选择
                                                    <font class="imageSites"><img src="/quanliadmin/docroot/images/comm/selects.jpg"></font>
                                                    </span>
                                                </div>

                                                <ul class="search_option_panel"  id="searchPanels" style="display: none;z-index: 100;">
                                                    <li class="childSelectImg" departmentID="" style="margin-top:5px;margin-bottom:5px;margin-left: 0px;font-size: 13px;" >请选择</li>
                                                    <!--{$department_select_html}-->
                                                </ul>

                                                <input type="hidden" value="" id="hdnSearchTypes" name="hdnSearchType">
                                                <input type="hidden" value="" id="search_departmentID" name="search_departmentID">
                                                <!--<input type="hidden" value="" id="departmentName" name="departmentName">-->
                                            </div>
                                        </span>

                                        <span>
                                       销售员：<select class="form-control w150" id="userID" name="userID">
                                                <option value="">请选择</option>
                                            </select>
                                    </span>
                                    <input type="hidden" id="operFlg" value="5">
                                    <input type="button" value="查询" class="btn btn-primary" onclick="account.search();" />
                                    <input type="button" value="重置" class="btn btn-warning" onclick="account.reset();" />
                                    <input type="button" value="导出" class="btn btn-success" onclick="account.excelout();" />
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>

            <table id="flex" style="display:none"></table>
            <table class="table table-bordered" style="width: 30% ;margin-top: 10px">
                <tr>
                    <th>应收金额</th>
                    <th>实收金额</th>
                    <th>未收金额</th>
                </tr>
                <tr>
                    <td id="receivable"></td>
                    <td id="receipts"></td>
                    <td id="uncollected"></td>
                </tr>
            </table>


        </div>

</div>

<div id="pop" style="display: none;">
    <div style="width:100%;">

        <div class="container">

            <div class="comm_content">

                <div class="commAttr">
                    <form id="edit_Form" class="form-horizontal" name="edit_Form" onsubmit="return false;">

                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span class="red">*</span> 客户信息：</label>

                            <div class="col-sm-3">
                                <input type="hidden" id="custID" name="custID" value="">
                                <input id="userName" name="custName" type="text" readonly="readonly" class="form-control" value="">
                            </div>
                            <div class="col-sm-3">
                                <button type="button" class="btn btn-primary" id="custBtn" onclick="searchCompany(1);">查询</button>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="custId" class="col-sm-3 control-label"><span class="red">*</span> 订单编号：</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control w300" id="saleCode" name="saleCode" placeholder="请输入订单编号" value="" >
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="payType" class="col-sm-3 control-label"><span class="red">*</span> 付款方式：</label>
                            <div class="col-sm-9">
                                <select id="paymentMethod" class="form-control input-sm"  name="paymentMethod" style="width:140px;">
                                    <option value="" selected>请选择</option>
                                    <!--{foreach from=$paymentMethod item=pay}-->
                                    <option value="<!--{$pay.itemID}-->"><!--{$pay.itemName}--></option>
                                    <!--{/foreach}-->
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span class="red">*</span> 金额：</label>
                            <div class="col-sm-9">
                                <div class="fl">
                                    <input type="text" class="form-control w100" id="changeAmount" name="changeAmount" value="0.00" >
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="remark" class="col-sm-3 control-label"> 备注：</label>
                            <div class="col-sm-9">
                                <textarea id="remark" class="form-control" name="remark"></textarea>
                            </div>
                            <input type="hidden" name="changeID" id="changeId" value="">
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    $("#flex").flexigrid({
        url:"/invokingAjax-backend/customer/financeChange.ajax?operFlg=1&type=1",
        dataType: "json",
        colModel : [
            {display: "流水号", name : "changeID", width : 80, sortable : true},
            {display: "客户名称", width : 100},
            {display: "订单号", width : 120},
            {display: "支付方式", width : 80},
            {display: "异动金额", width : 80},
            {display: "创建时间",align: "center", width : 140},
            {display: "异动状态",align: "center", width : 100},
            {display: "备注", width : 2000}
        ],
        <!--{if $edit_permission}-->
        buttons : [
            {name: "账户异动新增", bclass: "add", onpress : "account.add"},
        ],
        <!--{/if}-->
        sortname: "changeID",
        sortorder: "desc",
        usepager: true,
        rp: 10,
        useRp: true,
        showTableToggleBtn: true,
        autoload: true,
        onSubmit: function() {
            var dt = $("#search_form").serializeArray();
            $("#flex1").flexOptions({params: dt});
            return true;
        },
        onSuccess:function(){
            var dt = $("#search_form").serializeArray();
            E.ajax_post({
                url: "/invokingAjax-backend/customer/financeChange.ajax?operFlg=1&type=2",
                data: dt,
                call: function(result){
                    $("#receivable").html(result.receivable);
                    $("#receipts").html(-result.receipts);
                    $("#uncollected").html(result.uncollected);
                }
            });
        }
    });
    var account = {

        changeID:'',
        timeStamp:'',

        //搜索账户异动
        search: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt}).flexReload();
        },

        //重置
        reset: function() {
            document.getElementById('search_form').reset();
            $("#hdnSearchTypes").val('');
            $("#search_departmentID").val('');
            $("#searchOptions").html("请选择 <font class='imageSites'><img src='/quanliadmin/docroot/images/comm/selects.jpg'></font>");
            this.search();
        },

        //重新加载
        load: function() {
            $("#flex").flexReload();
        },

        //账户异动新增
        add: function( id ) {

            //调用打开弹出层公共JS方法
            E.popup.open({
                id:"pop",   		 //获取id为"pop"元素内的HTML
                title: id == null ? "正在操作：账户异动新增" : "正在操作：账户异动编辑",       //弹出层标题
                css: "width:800px;",     //设置弹出层样式
                btnName: id == null ? "账户异动新增" : "账户异动编辑",        //执行“确定”操作的按钮名称
                btnCall:"account.check();"  //点击确定后执行的方法
            });
            $(window).ready(function() {

                $('.square-radio').iCheck({
                    checkboxClass: 'icheckbox_square-blue',
                    radioClass: 'iradio_square-blue',
                    increaseArea: '20%' // optional
                });

            });

            if(id != null){
                $("#custBtn").css('cursor','not-allowed');
                $("#custBtn").attr('disabled',"disabled");
                $.ajax({
                    type: "POST",
                    url: "/invokingAjax-backend/customer/financeChange.ajax?operFlg=2&changeID="+id,
                    dataType: "JSON",
                    success: function(o) {
                        if(o.code == 200){
                            $('#custID').val(o.data.custID);
                            $('#userName').val(o.data.custName);
                            $("#saleCode").val(o.data.saleCode);
                            $("#paymentMethod").val(o.data.paymentMethod);
                            $("#changeAmount").val(o.data.changeAmount);
                            $("#remark").val(o.data.remark);
                            $("#changeId").val(o.data.changeID);
                        }else{
                            E.alert(o.message);
                        }
                    }
                });
            }

        },

        //验证获得收货地址相关数据
        check:function(){

            dt: "",
            this.dt = E.getFormValues("edit_Form");
            var custID = $.trim( $("#custID").val() );
            var saleCode = $("#saleCode").val();
            var paymentMethod = $("#paymentMethod").val();
            var changeAmount = $.trim( $("#changeAmount").val() );
            var err_msg = '';

            if(custID == ''){
                err_msg += '请选择客户<br />';
            }
            if(saleCode == ""){
                err_msg += '订单号不能为空<br />';
            }
            if(paymentMethod == ""){
                err_msg += '请选择支付方式<br />';
            }
            if(changeAmount == ""){
                err_msg += '金额数不能为空<br />';
            }

            if(err_msg != ''){
                E.alert(err_msg);
            }else{
                account.edit();
            }

        },

        edit:function(){
            E.popup.close();
            E.loadding.open("正在保存，请稍候...");
            E.ajax_post({
                url: "/invokingAjax-backend/customer/financeChange.ajax?operFlg=100&act=edit",
                data: this.dt,
                call: "account.result"
            });
        },

        result:function(o){
            if (o.code == 200) {
                E.loadding.close();
                E.alert(o.message, 2, "account.load");
            } else {
                E.alert(o.message);
            }
        },
        //导出
        excelout: function (){
            E.confirm('确认导出？',function () {
                $("#operFlg").attr("name", 'operFlg');
                $("#search_form").attr("action", "/invokingAjax-backend/customer/financeChange.ajax?operFlg=5");
                $("#search_form").attr("onsubmit", "return true");
                $("#search_form").submit();
                $("#operFlg").attr("name", null);
                $("#search_form").attr("onsubmit", "return false");
            })
        },

    };
    $(function () {
        //日期
        $('#startDate').datepicker();
        $('#endDate').datepicker();

    })
    //清空日期
    function timeClear1() {
        $('#startDate').val('');
        $('#endDate').val('');
    }

    //部门销售人员
    $(window).ready(function() {


        $('#searchPanels').find('li').click(function() {

            var departmentID = $(this).attr('departmentID');
            if (departmentID > 0) {

                E.ajax_get({
                    url: '/invokingAjax-backend/company/company.ajax?operFlg=2',
                    data: {
                        departmentID: departmentID
                    },
                    call: function( o ) {

                        if (o.code == 200) {

                            var html = '<option value="">请选择</option>';
                            if ( o.data ) {
                                $.each( o.data, function( k, v ) {
                                    html += '<option value="' + v.userID + '">' + v.trueName + '</option>';
                                });
                            }
                            $('#userID').html(html);

                        } else {

                            E.alert( o.message);

                        }

                    }
                });

            } else {
                var html = '<option value="">请选择</option>';
                $('#userID').html(html);
            }

        });

    });

    //查询客户
    function searchCompany (page) {
        var_saleCode = $("#saleCode").val();
        var_paymentMethod = $("#paymentMethod").val();
        var_changeAmount = $.trim( $("#changeAmount").val() );
        var_remark = $("#remark").val();

        var company_name="";
        if($("#searchCompanyName").val()!=undefined){
            company_name = $("#searchCompanyName").val();
        }

        E.loadding.open('正在查询，请稍候...');

        E.ajax_post({
            url:  "/invokingAjax-backend/company/company.ajax?operFlg=1&company_name="+company_name,
            data: {
                sortname: 'company_id',
                sortorder: 'ASC',
                rp: 10,
                page: page,
                list_type: 'general',
                show_type: 'company',
                way_type:'searchCompany'
            },
            call: function( o ) {

                E.loadding.close();
                if (o.data) {

                    var html_str = '<table><tr><td style="width: 80px;">公司名称：</td><td><input type="text" class="form-control w300" id="searchCompanyName" name="searchCompanyName" value='+o.company_name+'></span></td><td><input type="button" value="查询" id="searchBtn" class="btn btn-primary" onclick="searchCompany(1);" /></td></tr></table>';
                    html_str += '<table class="s">';
                    html_str += '<tbody>';

                    html_str += '<tr>';
                    html_str += '<th width="80">操作</th>';
                    html_str += '<th width="*">公司名称</th>';
                    html_str += '<th width="100">联系人</th>';
                    html_str += '<th width="100">联系方式</th>';
                    html_str += '<th width="180">部门</th>';
                    html_str += '<th width="100">销售员</th>';

                    html_str += '</tr>';
                    $.each(o.data, function(k, v) {

                        if (v.mobile) {
                            var contact_way = v.mobile;
                        } else {
                            var contact_way = v.phone;
                        }

                        html_str += '<tr>';
                        html_str += '<td class="tac"><a href="javascript:void(0)" class="company_line" val0='+v.company_id+' val1='+v.company_name+' val2='+ v.connect_name+' val3='+ contact_way +' onclick="changeCompany('+v.company_id+');">选择</a></td>';
                        html_str += '<td class="tac" style="text-align:left">' + v.company_name + '</td>';
                        html_str += '<td class="tac">' + v.connect_name + '</td>';
                        html_str += '<td class="tac">' + contact_way + '</td>';
                        html_str += '<td class="tac">' + v.departmentName + '</td>';
                        html_str += '<td class="tac">' + v.userName + '</td>';
                        html_str += '</tr>';

                    });
                    html_str += '</tbody>';
                    html_str += '</table>';

                    if (o.paging) {
                        html_str += o.paging;
                    }

                    E.popup.open({
                        content: html_str,
                        title: '大客户信息列表',
                        css: 'width: 800px;'
                    });

                }else{
                    var html_str = '<table><tr><td style="width: 80px;">公司名称：</td><td><input type="text" class="form-control w300" id="searchCompanyName" name="searchCompanyName" value='+o.company_name+'></span></td><td><input type="button" value="查询" id="searchBtn" class="btn btn-primary" onclick="searchCompany(1);" /></td></tr></table>';
                    html_str += '<table class="s">';
                    html_str += '<tbody>';

                    html_str += '<tr>';
                    html_str += '<th width="80">操作</th>';
                    html_str += '<th width="*">公司名称</th>';
                    html_str += '<th width="100">联系人</th>';
                    html_str += '<th width="100">联系方式</th>';
                    html_str += '<th width="180">部门</th>';
                    html_str += '<th width="100">销售员</th>';

                    html_str += '</tr>';
                    html_str += '</tbody>';
                    html_str += '</table>';
                    E.popup.open({
                        content: html_str,
                        title: '大客户信息列表',
                        css: 'width: 800px;'
                    });
                }
            }
        });
    }

    //选择客户
    function changeCompany (searchCompanyID){
        var custID;
        var custName;
        E.ajax_post({
            url: '/invokingAjax-backend/company/company.ajax?operFlg=100&act=search',
            data: {
                company_id: searchCompanyID
            },
            call: function( o ) {
                if (o.code == 200) {
                    if ( o.data ) {
                        $.each( o.data, function( k, v ) {
                            custID = v.company_id;
                            custName = v.company_name;
                        });
                    }
                } else {
                    E.alert( o.message);
                }
                E.popup.close();
                account.add();
                $('#custID').val(custID);
                $('#userName').val(custName);
                $('#saleCode').val(var_saleCode);
                $('#paymentMethod').val(var_paymentMethod);
                $('#changeAmount').val(var_changeAmount);
                $('#remark').val(var_remark);
            }
        });
    }
</script>

</body>
</html>